package com.liquidhorse.gui;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

public final class Tray {
	
	private TrayIcon icon = null;
	
	public void setTrayIcon(final JFrame f) {
		if (SystemTray.isSupported()) {
			SystemTray tray = SystemTray.getSystemTray();
			icon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(this.getClass().getClassLoader().getResource("icon_15.png")), "LiquidHorse");
			icon.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					f.setVisible(true);
					f.setState(JFrame.NORMAL);
					f.toFront();
				}
			});
			try {
				tray.add(icon);
			} catch (AWTException e) {
				e.printStackTrace();
			}
		}
	}

	public void showInfoMsg(String msg, String title) {
		icon.displayMessage(title, msg, TrayIcon.MessageType.INFO);
	}

	public void showErrorMsg(String msg, String title) {
		icon.displayMessage(title, msg, TrayIcon.MessageType.ERROR);

	}

	public void showWarningMsg(String msg, String title) {
		icon.displayMessage(title, msg, TrayIcon.MessageType.WARNING);

	}

	public void showMsg(String msg, String title) {
		icon.displayMessage(title, msg, TrayIcon.MessageType.NONE);
	}
}
